/*****************************************************
** Author: 
** Date: 2019-11-14
*
*****************************************************/

#ifndef __BIPBUFFER_H_
#define __BIPBUFFER_H_

#ifdef __cplusplus
extern "C"{
#endif


/*!
 *  @brief: Type for Bip buffer.
 */
struct bipbuf
{
   	// Continous data partition A size.
    unsigned int 	partitionASize;   
    // Continous data partition A start index.
    unsigned int   	partitionAIndex;    
    // Continous data partition B size.
    unsigned int  	partitionBSize;     
    // Continous data partition B start index.
    unsigned int  	partitionBIndex;    
    // Reserved data block size.
    // @todo   do we need nested reserve support for simultanous usage?
    unsigned int  	reservedSize;   
    // Reserved data block start index.
    unsigned int  	reservedIndex;    
    // Size of the usable buffer area.
    // memorySize
    unsigned int   	bufferSize;
    // Pointer to usable buffer base address.
    // memoryBaseAddress
    char    		buffer[1];
};

int bipbuffer_construct(struct bipbuf* _this, unsigned int size);
void bipbuffer_destroy(struct bipbuf* _this);
void* bipbuffer_reserve(struct bipbuf* _this, unsigned int size);
void bipbuffer_commit(struct bipbuf* _this, unsigned int size);
void* bipbuffer_get(struct bipbuf* _this, unsigned int* countinousBlockSizePtr);
void bipbuffer_decommit(struct bipbuf* _this, unsigned int size);
unsigned int bipbuffer_usedsize(struct bipbuf* _this);


#ifdef __cplusplus
}
#endif

#endif /* __BIPBUFFER_H_ */

